﻿
Public Class CamcopForm
    Inherits KryptonForm

    'Form Events :
    Private Sub CamcopForm_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Control.CheckForIllegalCrossThreadCalls = False
        SelectPage(CHP)
    End Sub
    'From Closing :
    Private Sub CamcopForm_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim dr As DialogResult = KryptonMessageBox.Show("Are you sure you want close this camera ?", "Close Camcop", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If dr = Windows.Forms.DialogResult.Yes Then
            If _Camera IsNot Nothing Then
                _Camera.Dispose()
                _Camera = Nothing
            End If
        Else
            e.Cancel = True
        End If
    End Sub
    'Show About Form :
    Private WithEvents _AboutForm As CamcopAboutForm
    Private Sub BSA_About_Click(sender As System.Object, e As System.EventArgs) Handles BSA_About.Click
        BSA_About.Enabled = ButtonEnabled.False
        _AboutForm = New CamcopAboutForm
        _AboutForm.Show()
    End Sub
    Private Sub _AboutForm_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles _AboutForm.FormClosed
        BSA_About.Enabled = ButtonEnabled.True
    End Sub
    'Select Page :
    Private Sub SelectPage(ByVal pan As UserControl)
        Me.SuspendLayout()
        CP.Visible = False
        CHP.Visible = False
        pan.Visible = True
        BSA_Shutdown.Visible = CP.Visible
        Me.ResumeLayout()
    End Sub
    'Shutdown Camera :
    Private Sub BSA_Shutdown_Click(sender As System.Object, e As System.EventArgs) Handles BSA_Shutdown.Click
        Dim dr As DialogResult = KryptonMessageBox.Show("Are you sure you want shutdown this camera ?", "Shutdown Camera", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If dr = Windows.Forms.DialogResult.Yes Then
            If _Camera IsNot Nothing Then
                _Camera.Dispose()
                _Camera = Nothing
            End If
            SelectPage(CHP)
        End If
    End Sub
    'Camera :
    Private _Camera As Camera
    Private Sub CHP_CameraLoadRequested(sender As Object, e As CameraLoadRequestedEventArgs) Handles CHP.CameraLoadRequested
        Dim infos As ICameraInfos = e.CameraInfos
        _Camera = New Camera(infos)
        CP.SelectedCamera = _Camera
        SelectPage(CP)
    End Sub

End Class
